<?php

namespace App\Http\Middleware;

use Closure;
use Overtrue\Socialite\User as SocialiteUser;


class SimulatedWechatUser
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (config('app.env') === 'local') {
            $user = [
                'openid' => 'aaaaaaaaaaaaa',
                'nickname' => '禹声',
                'headimgurl' => 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1529748356279&di=a1d29d7ca2e45a1c4e1d1ac71a0eda22&imgtype=0&src=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201609%2F15%2F20160915075853_NdiBU.jpeg',
            ];

            $user = new SocialiteUser([
                'id' => array_get($user, 'openid'),
                'name' => array_get($user, 'nickname'),
                'nickname' => array_get($user, 'nickname'),
                'avatar' => array_get($user, 'headimgurl'),
                'email' => null,
                'original' => [],
                'provider' => 'WeChat',
            ]);

            session(['wechat.oauth_user.default' => $user]);

        }
        return $next($request);
    }
}
